<template>
	<view class="pages">
		<my-header bgColor="bg-gradual-blue" :isBack="true" >
			<block slot="backText">返回</block>
			<block slot="content">订单列表</block>
		</my-header>
        <view class="state_list row" v-if="is_state">
            <view class="state col" :class="flg==item.flg?'cur':''" v-for="(item,index) in state_list" :key="index" @click="initData(item.flg)">
                {{item.name}}
            </view>
        </view>
        <view class="order_list col">
            <view class="order_item" v-for="(item,index) in order_list" :key="index">
                <view class="head row">
                    <!-- <view class="order_id">订单号：{{item.order_id}}</view> -->
                    <view class="creat_time">下单时间：{{item.create_time}}</view>
                    <view class="state">{{item.state}}</view>
                </view>
                <view class="row" >
                    <image class="main_img" :src="item.main_img" mode="" />
                    <view class="main">
                        <view class="title">{{item.title}}</view>
                        <view class="row">
                            <!-- <view class="price">预估价格：{{item.price}}</view> -->
                            <!-- <view class="price">预计返利：{{item.discount_price}}</view> -->
                        </view>
                        <!-- <view class="row"> -->
                            <view class="price">支付：{{item.pay_price}}</view>
                            <view class="price">返利：{{item.money}}</view>
                        <!-- </view> -->
                    </view>
                </view>
            </view>
        </view>
        <!-- <view class="bottom"></view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
                state_list:[
                    {
                        flg:0,
                        name:"全部",
                    },

                    {
                        flg:1,
                        name:"待付款",
                    },
                    {
                        flg:2,
                        name:"已付款",
                    },
                    {
                        flg:3,
                        name:"已完成",
                    },
                    {
                        flg:4,
                        name:"无效",
                    }
                ],
                flg:0,
                order_list:[],
                is_state:false
			}
		},
		onLoad(options) {
           this.initData()
		},
		methods: {
            async initData(state=0){
                this.flg=state
				const openid=await uni.$get_openId()
                const res=await uni.$request({
                    state
                },"api/jd/get_order_list")
                if (res.code==200) {
                    this.order_list=res.data.order_list
                    this.is_state=res.data.is_state
                } else{
                    uni.$err(res.msg)
                }
                console.log(res.data);
            },
            copy(data){
                uni.setClipboardData({
                    data,
                    success: function () {
                        console.log('success');
                    }
                });
            },
            open(url){
                console.log(url);
                uni.navigateTo({
                     url
                });
            }
		}
	}
</script>

<style lang="scss">
	@import "./index";
</style>